package com.heima.feign.falback;

import com.heima.model.wemedia.pojos.WmNews;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.feign.WemediaFeignClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class WemediaFeignFallback implements FallbackFactory<WemediaFeignClient> {
    @Override
    public WemediaFeignClient create(Throwable throwable) {
        return new WemediaFeignClient() {
            @Override
            public ResponseResult<WmUser> save(WmUser wmUser) {

                log.info("参数:{}",wmUser);
                log.error("WemediaFeignClient 的调用，save方法，出错了{}",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
            }
            @Override
            public ResponseResult<WmUser> findByName(String name) {
                log.info("参数:{}",name);
                log.error("WemediaFeignClient 的调用，findByName方法，出错了{}",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
            }

            @Override
            public ResponseResult<WmNews> findWmNewsById(Integer id) {
                log.info("参数:{}",id);
                log.error("WemediaFeignClient 的调用，findWmNewsById方法，出错了{}",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
            }

            @Override
            public ResponseResult updateWmNews(WmNews wmNews) {
                log.info("参数:{}",wmNews);
                log.error("WemediaFeignClient 的调用，updateWmNews方法，出错了{}",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
            }
        };
    }
}
